<template>
	<view class="bakc">
		<view class="back_comp">
			<view style="width: 60rpx;"></view>
			<view style="width: 60rpx;" @click="back" >
				<image v-if="isReturn"  src="/static/icon/left.png" style="width: 20rpx;height: 40rpx;" />
			</view>
			<view style="width: 500rpx; ">
				<view style="width: 520rpx; text-align: center; ">
					{{text}}
				</view>
			</view>
			<view v-if="isReturn"></view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			text: {
				type: String,
				default: '返回组件'
			},
			isReturn: {
				type: Boolean,
				default: false
			},
			path: {
				type: String,
				default: ''
			}
		},
		name: "back",
		data() {
			return {

			};
		},
		methods: {
			back() {
				if(!this.isReturn){
					return;
				}
				if (this.path) {
					if (this.path === '/pages/main/main') {
						uni.switchTab({
							url: '/pages/main/main'
						})
					} else if (this.path === 'pages/equipment/equipment') {
						//断开蓝牙连接
						this.closeBLEConnection();
						uni.$u.route({
							type: 'redirect',
							url: "pages/equipment/equipment"
						})
					} else {
						uni.$u.route({
							type: 'redirect',
							url: this.path
						})
					}
				} else {
					this.$u.route({
						type: 'navigateBack',
						delta: 1
					})
				}
			},
			closeBLEConnection() {
				uni.closeBLEConnection({
					deviceId: this.vuex_device_id
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.bakc {
		width: 100%;

		.back_comp {
			height: 120rpx;
			padding-top: 65rpx;
			display: flex;
			align-items: center;
			font-size: 35rpx;
			font-weight: 600;
			background: rgb(53, 53, 53);
			color: #EDEDED;
		}
	}
</style>